from pydantic import BaseModel, Field
from typing import Optional, List
from datetime import datetime


class TaskInfo(BaseModel):
    """任务信息基础DTO"""
    task_id: str = Field(..., description="任务ID")
    original_filename: str = Field(..., description="原始文件名")
    status: str = Field(..., description="任务状态")
    progress: int = Field(0, description="任务进度(0-100)")
    created_at: datetime = Field(..., description="创建时间")


class TaskDetailInfo(TaskInfo):
    """任务详细信息DTO"""
    user_openid: Optional[str] = Field(None, description="用户OpenID")
    file_size: Optional[int] = Field(None, description="文件大小(字节)")
    video_format: Optional[str] = Field(None, description="视频格式")
    video_url: Optional[str] = Field(None, description="视频链接")
    audio_url: Optional[str] = Field(None, description="音频链接")
    audio_format: Optional[str] = Field(None, description="音频格式")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    error_message: Optional[str] = Field(None, description="错误信息")
    started_at: Optional[datetime] = Field(None, description="开始处理时间")
    completed_at: Optional[datetime] = Field(None, description="完成时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")


class VideoUploadResponse(BaseModel):
    """视频上传响应DTO"""
    task_id: str = Field(..., description="任务ID")
    original_filename: str = Field(..., description="原始文件名")
    file_size: Optional[str] = Field(None, description="文件大小(格式化)")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    video_url: Optional[str] = Field(None, description="视频链接")
    status: str = Field(..., description="任务状态")
    created_at: datetime = Field(..., description="创建时间")


class TaskStatusResponse(BaseModel):
    """任务状态响应DTO"""
    task_id: str = Field(..., description="任务ID")
    original_filename: str = Field(..., description="原始文件名")
    status: str = Field(..., description="任务状态")
    progress: int = Field(..., description="任务进度(0-100)")
    video_url: Optional[str] = Field(None, description="视频链接")
    audio_url: Optional[str] = Field(None, description="音频链接")
    duration: Optional[float] = Field(None, description="视频时长(秒)")
    file_size: Optional[str] = Field(None, description="文件大小(格式化)")
    audio_format: Optional[str] = Field(None, description="音频格式")
    error_message: Optional[str] = Field(None, description="错误信息")
    created_at: datetime = Field(..., description="创建时间")
    started_at: Optional[datetime] = Field(None, description="开始处理时间")
    completed_at: Optional[datetime] = Field(None, description="完成时间")


class UserTasksResponse(BaseModel):
    """用户任务列表响应DTO"""
    tasks: List[TaskInfo] = Field(..., description="任务列表")
    total: int = Field(..., description="任务总数")


class AudioDownloadResponse(BaseModel):
    """音频下载响应DTO"""
    task_id: str = Field(..., description="任务ID")
    original_filename: str = Field(..., description="原始文件名")
    audio_url: str = Field(..., description="音频下载链接")
    audio_format: str = Field(..., description="音频格式")
    duration: Optional[float] = Field(None, description="音频时长(秒)")
    file_size: Optional[str] = Field(None, description="文件大小(格式化)")


class SupportedFormatsResponse(BaseModel):
    """支持格式响应DTO"""
    video_formats: List[str] = Field(..., description="支持的视频格式")
    audio_formats: List[str] = Field(..., description="支持的音频格式")
    max_file_size: int = Field(..., description="最大文件大小(字节)")
    max_file_size_display: str = Field(..., description="最大文件大小(显示)")


class SystemStatusResponse(BaseModel):
    """系统状态响应DTO"""
    ffmpeg_available: bool = Field(..., description="FFmpeg是否可用")
    ffmpeg_version: Optional[str] = Field(None, description="FFmpeg版本")
    processing_tasks: int = Field(..., description="正在处理的任务数")
    max_concurrent_tasks: int = Field(..., description="最大并发任务数")
    temp_dir_available: bool = Field(..., description="临时目录是否可用")
    temp_dir_space: Optional[str] = Field(None, description="临时目录可用空间")


class TaskOperationResponse(BaseModel):
    """任务操作响应DTO"""
    task_id: str = Field(..., description="任务ID")
    message: str = Field(..., description="操作结果消息")
    success: bool = Field(..., description="操作是否成功")